#!/usr/bin/env php
<?php

`/opt/ethos/bin/bootlog ethos-stats-daemon`;

@ob_end_clean();

require_once('/opt/ethos/lib/functions.php');

if($argv[1]){

  $log = send_data();
  require_once('/opt/ethos/lib/ethos-stats-dump.php');

  echo "Sent updated stats to webhook!\n";
  exit();

}

sleep(10); //this is needed so that rig gets ip before initial stats run

while(true){
	$client = new WebSocketClient(); 
	$client->connect("60.2.177.174", 8082, '/'); //end write by warren 
	$json = json_encode($send);
	$send = get_stats();
	
	$client->sendData($json);

        require_once("/opt/ethos/bin/hash-monitor");
        $log = send_data();
	file_put_contents("/var/run/ethos/stats.file",$log);
	
	$uptime = trim(`cut -d " " -f1 /proc/uptime | cut -d "." -f 1`);
	
	/*
	if($uptime < 3600){
        	sleep(120);
	} else {
		sleep(180);
	}*/
	
}

?>
